package com.example.finalapplication;

import android.app.Activity;
import android.content.SharedPreferences;
import android.view.View;
import android.widget.ImageButton;

import androidx.appcompat.app.AlertDialog;

public class LogTask extends LogActivity {

    public void onClick(View v) {
        ImageButton elatedButton = (ImageButton) findViewById(R.id.running);
        elatedButton.setOnClickListener(new View.OnClickListener() {
            SharedPreferences preferences = getSharedPreferences("times", Activity.MODE_PRIVATE);
            int e = preferences.getInt("times", 1);

            @Override
            public void onClick(View view) {
                SharedPreferences pre = getSharedPreferences("times", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = pre.edit();
                editor.putInt("times", elatedTimes++);
                editor.apply();

                AlertDialog.Builder builder = new AlertDialog.Builder(LogTask.this);
                builder.setTitle("提示").setMessage("打卡成功！你已累计进行有氧运动" + e + "天")
                        .setNegativeButton("返回", null);
                builder.create().show();

                editor.putInt("times", e+1);
                editor.apply();

            }
        });
    }

    public void onClick1(View v) {

        ImageButton elatedButton1 = (ImageButton) findViewById(R.id.button_less);
        elatedButton1.setOnClickListener(new View.OnClickListener() {
            SharedPreferences preferences1 = getSharedPreferences("times1", Activity.MODE_PRIVATE);
            int e = preferences1.getInt("times1", 1);
            @Override
            public void onClick(View view) {

                SharedPreferences sp = getSharedPreferences("times1",Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = sp.edit();
                editor.putInt("times1", elatedTimes1++);
                editor.apply();


                AlertDialog.Builder builder = new AlertDialog.Builder(LogTask.this);
                builder.setTitle("提示").setMessage("打卡成功！你已累计进行无氧运动" + e + "天")
                        .setNegativeButton("返回", null);
                builder.create().show();

                editor.putInt("times1", e+1);
                editor.apply();
            }
        });
    }
    public void onClick2(View v) {

        ImageButton elatedButton2 = (ImageButton) findViewById(R.id.button_small);
        elatedButton2.setOnClickListener(new View.OnClickListener() {
            SharedPreferences preferences2 = getSharedPreferences("times2", Activity.MODE_PRIVATE);
            int e = preferences2.getInt("times2", 1);
            @Override
            public void onClick(View view) {

                SharedPreferences pref = getSharedPreferences("times2", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = pref.edit();
                editor.putInt("times2", elatedTimes2++);
                editor.apply();


                AlertDialog.Builder builder = new AlertDialog.Builder(LogTask.this);
                builder.setTitle("提示").setMessage("打卡成功！你已累计进行小球类运动" + e + "天")
                        .setNegativeButton("返回", null);
                builder.create().show();

                editor.putInt("times2", e+1);
                editor.apply();
            }

        });
    }
    public void onClick3(View v){
        ImageButton elatedButton3 = (ImageButton)findViewById(R.id.button_yoga);
        elatedButton3.setOnClickListener(new View.OnClickListener() {
            SharedPreferences preferences3 = getSharedPreferences("times3", Activity.MODE_PRIVATE);
            int e = preferences3.getInt("times3", 1);
            @Override
            public void onClick(View view) {

                SharedPreferences preff = getSharedPreferences("times3", Activity.MODE_PRIVATE);
                SharedPreferences.Editor editor = preff.edit();
                editor.putInt("times3", elatedTimes3++);
                editor.apply();

                AlertDialog.Builder builder = new AlertDialog.Builder(LogTask.this);
                builder.setTitle("提示").setMessage("打卡成功！你已累计进行瑜伽" + e + "天")
                        .setNegativeButton("返回", null);
                builder.create().show();

                editor.putInt("times3", e+1);
                editor.apply();
            }

        });
    }
}
